<template>
  <el-echarts theme="macarons" :option="option"></el-echarts>
</template>
<script>
import { echartsXFormatter } from '@vimi/utils-tool'

export default {
  components: {},
  props: {},
  data() {
    return {
      orgClass: '',
      option: null,
    }
  },
  computed: {
    bankCode() {
      return this.$store.getters.user.orgCode
    },
  },
  watch: {},
  created() {
    this.orgClass = this.$utils.getClientOrgClass()
    this.getData()
  },
  mounted() {},
  methods: {
    async getData() {
      let addressCode = this.$utils.getAddressCode()
      // let submitType = this.orgClass === 'org_gov_ny' ? '1' : '4'
      const [res] = await this.$utils.promise(
        this.$http.get(
          `/industrial/customer/bank/collect1/?addressCode=${addressCode}&bankCode=${this.bankCode}`
        )
      )
      let xData = []
      let aData = []
      let bData = []
      let cData = []
      let dData = []
      // let amountAll = 0
      if (res && res.data) {
        // for (const p of res.data) {
        xData = res.data.entityTypeNameList
        aData = res.data.supplyCountList
        bData = res.data.approvalCountList
        cData = res.data.supplyFundsList
        dData = res.data.approvalFundsList
      }

      // bData = aData.map(item => {
      //   return amountAll > 0 ? Math.round(item / amountAll * 10000) / 100 : '-'
      // })

      const chartData = {
        title: '产业分析',
        subtext: '',
        legend: ['申请的项目数', '审批的项目数', '申请的项目金额', '审批的项目金额'],
        xData: xData,
        seriesData: [
          {
            name: '申请的项目数',
            type: 'bar',
            barMaxWidth: 60,
            yAxisIndex: 1,
            data: aData,
          },
          {
            name: '审批的项目数',
            type: 'bar',
            yAxisIndex: 1,
            data: bData,
          },
          {
            name: '申请的项目金额',
            type: 'bar',
            yAxisIndex: 0,
            data: cData,
          },
          {
            name: '审批的项目金额',
            type: 'bar',
            yAxisIndex: 0,
            data: dData,
          },
        ],
      }
      this.setOption(chartData)
    },

    setOption(data) {
      this.option = {
        title: {
          text: data.title,
          subtext: data.subtext,
        },
        tooltip: {
          trigger: 'axis',
        },
        legend: {
          data: data.legend,
        },
        toolbox: {
          show: true,
          feature: {
            mark: { show: true },
            dataView: { show: true, readOnly: false },
            magicType: { show: true, type: ['line', 'bar'] },
            restore: { show: true },
            saveAsImage: { show: true },
          },
        },
        grid: {
          top: 80,
          left: 50,
          right: 50,
        },
        xAxis: [
          {
            type: 'category',
            data: data.xData,
            axisLabel: {
              formatter: v => echartsXFormatter(v),
            },
          },
        ],
        yAxis: [
          {
            type: 'value',
            name: '金额（万元）',
          },
          {
            type: 'value',
            name: '数量(个)',
          },
        ],
        series: data.seriesData,
      }
    },
  },
}
</script>
<style scoped></style>
